<?php
namespace app\admin\model;
use think\Model;

class Article extends Model{
  public function getTree(){
    $data=$this->select();//按sort的倒序排
    // dump($data);die;
    return $this->sort($data);
  }
  public function sort($data,$pid=0,$level=0){
    static $tree=[];
    foreach ($data as $k => $v) {
      if ($v['pid']==$pid) {
          $v['level']=$level;
        $tree[]=$v;
        $this->sort($data,$v['cid'],$level+1);
      }
    }
      return $tree;
   }
}


 ?>
